﻿using System.Text.Json;

namespace ymk_camera_surveillance.Req
{

    internal class TokenClient
    {
        private static HttpClient client = null;
        private static string authorizationKey = "";
        private static string Url = "";



        private static async Task<HttpClient> GetTokenClient()
        {
            if (client != null)
                return client;

            client = new HttpClient();

            if (string.IsNullOrEmpty(authorizationKey))
            {
                authorizationKey = await client.GetStringAsync($"{Url}login");
                authorizationKey = JsonSerializer.Deserialize<string>(authorizationKey);
            }

            client.DefaultRequestHeaders.Add("Authorization", authorizationKey);
            client.DefaultRequestHeaders.Add("Accept", "application/json");

            return client;
        }

        public static HttpClient GetClient()
        {
            if (client != null)
                return client;

            client = new HttpClient();
            return client;
        }
    }
}
